package me.helllp.dake.core;

import com.github.yitter.contract.IdGeneratorOptions;
import lombok.Getter;
import lombok.Setter;
import me.helllp.dake.core.config.IdGenConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE)
@ComponentScan("me.helllp.dake.core")
@Getter
@Setter
@PropertySource("classpath:dake_core.properties")
public class DakeCoreConfig {
    /**
     * ID生成器
     *
     * @param config id生成器配置类
     * @return ID生成器
     */
    @Bean("dakeIdGenerator")
    public IdGenerator idGenerator(IdGenConfig config) {
        IdGeneratorOptions options = new IdGeneratorOptions(config.getWorkerId());
        options.SeqBitLength = config.getSeqBitLength();
        options.WorkerIdBitLength = config.getWorkerIdBitLength();
        return new IdGenerator();
    }
}
